import 'package:flutter/material.dart';

// 延迟构建组件
class DelayedBuildView extends StatefulWidget {
  final Widget child;
  final Duration delay;
  final Widget? placeholder;

  const DelayedBuildView({
    Key? key,
    required this.child,
    this.delay = const Duration(seconds: 1),
    this.placeholder,
  }) : super(key: key);

  @override
  _DelayedBuildViewState createState() => _DelayedBuildViewState();
}

class _DelayedBuildViewState extends State<DelayedBuildView> {
  Widget _currentChild = const SizedBox.shrink();

  @override
  void initState() {
    super.initState();
    _currentChild = widget.placeholder ?? const SizedBox.shrink();
    Future.delayed(widget.delay, () {
      if (mounted) setState(() => _currentChild = widget.child);
    });
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedSwitcher(
      duration: widget.delay,
      child: _currentChild,
    );
  }
}
